<template>
	<view>
		<view class="list p30">
			<view v-for="(v,i) in data" :key="i" class="list_box bgw">
				<topUser :userData="v.users"></topUser>
				<p @tap="GoDynamicDetails(v,i)" class="texte">
					<span v-for="(j,k) in v.markets" :key="k" @tap="GoJi(j)" class="c1">
						#{{j.name}}#
					</span>
					{{v.title}} 
				</p>
				<view @tap="GoDynamicDetails(v,i)" class="imagesArr">
					<image v-for="(img,imgK) in v.images" :key="imgK" :src="img+'?x-oss-process=image/resize,m_lfit,h_200,w_200'" mode="aspectFit"></image>
					<image v-if="v.videoCover != '' " :src="v.videoCover+'?x-oss-process=image/resize,m_lfit,h_200,w_200'"  mode="aspectFit"></image>
				</view>
				<view class="goods">
					<goods v-for="(a,b) in v.products" :key="b" :goodsData="a"></goods>
				</view>
				<view class="bottom">
					<view class="fl">
						浏览量 {{v.hits}}
					</view>
					<view class="fr">
						<span>
							<image @tap="like(v.id,i)" v-if="!v.isPraise" src="../../../static/image/icon_like_narmal@2x.png"></image>
							<image @tap="nolike(v.id,i)" v-if="!!v.isPraise" src="../../../static/image/icon_like_select@2x.png"></image>
							{{v.praiseQuantity}}
						</span>
						<span @tap="GoDynamicDetails(v,i)">
							<image src="../../../static/image/reply.png"></image>
							{{v.commentQuantity}}
						</span>
						<span @tap="GoShare(v)">
							<image src="../../../static/image/share.png"></image>
							分享
						</span>
					</view>
				</view>
			</view>
		</view>
		<view v-if="data == '' " class=" dataNone">
			<image src="../../../static/image/guanzhu@2x.png" mode=""></image>
			<p>暂无关注</p>
		</view>
	</view>
</template>

<script>
	import topUser from '@/components/top_user/top_user.vue'
	import goods from '@/components/goods/goods.vue'
	import {
		DynamicMy,
		DynamicPraise,
		DynamicCancelPraise
	} from '../../../api/api.js'
	export default {
		components: {
			topUser,
			goods
		},
		data() {
			return {
				data: [],
				stops: 0,
				pageNumber: 1,
				pageSize: 10

			}
		},
		mounted() {
			var that = this;
			uni.$on("updateDynamicAttribute",function(e){
				console.log(e);
				var index = e.index;
				if(!!index && that.data[index]){
					that.data[index].isPraise = e.isPraise;
					that.data[index].commentQuantity = !!e.commentQuantity?e.commentQuantity:that.data[index].commentQuantity;
					that.data[index].praiseQuantity = !!e.praiseQuantity?e.praiseQuantity:that.data[index].praiseQuantity;
					that.$forceUpdate();
				}
			})
		},
		methods: {
			GoShare(v){
				uni.setStorageSync('judouPoster',v)
				this.$navigateTo('../share/share?type=dynamic')
			},
			checking(){
				if(this.stops == 0){
					this.init()
				}
			},
			async like(id, i) {
				let data = await DynamicPraise({
					id: id
				})
				if (data.code == 0) {
					this.data[i].isPraise = true
					this.data[i].praiseQuantity++
				}
			},
			async nolike(id, i) {
				let data = await DynamicCancelPraise({
					id: id
				})
				if (data.code == 0) {
					this.data[i].isPraise = false
					this.data[i].praiseQuantity--
				}
			},
			GoGoodsDetails(id) {
				this.$navigateTo('../GoodsDetails/GoodsDetails?id=' + id)
			},
			GoDynamicDetails(v,index) {
				v.hits++;
				this.$navigateTo('../DynamicDetails/DynamicDetails?id=' + v.id+'&index='+index)
			},
			inits() {
				this.stops = 0
				this.pageNumber = 1
				this.data = []
				this.init()
			},
			async init() {
				let parameret = {
					pageable: {
						pageNumber: this.pageNumber,
						pageSize: this.pageSize
					},
					isFollow: true
				}
				let data = await DynamicMy(parameret)
				data = data.data
				if (data.length != this.pageSize) {
					this.stops = 0
				}
				for (let i = 0; i < data.length; i++) {
					data[i].users = {
						name: data[i].member.eperAccount.eperUsername,
						img: data[i].member.eperAccount.eperAvatarImg,
						state: 1,
						createdDate: data[i].createdDate.slice(0, 10),
						id: data[i].member.id,
						isCreator: false,
						isFollow: true
					}
				}
				this.data = [...this.data, ...data]
				this.pageNumber = this.pageNumber + 1
			},
			GoJi(v) {
				this.$navigateTo('../ji/ji?id=' + v.id)
			},
		}
	}
</script>

<style lang="less" scoped>
	@import './index.less';
</style>
